package com.mingqi.enetconnected.view.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.view.treechoose.listener.OnDialogCloseListener;
import com.mingqi.enetconnected.view.treechoose.listener.OnTreeChooseCompleteListener;
import com.mingqi.enetconnected.view.treechoose.widget.TreeLevelChoose;

/**
 * Created by li on 2018/8/16.
 * WeChat 18571658038
 * author LiWei
 */

public class BottomDialog extends Dialog {

    private TreeLevelChoose mLevelChoose;

    public BottomDialog(Context context) {
        super(context, R.style.my_bottom_dialog);
        init(context);
    }

    public BottomDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    /**
     * 初始化
     *
     * @param context
     */
    private void init(Context context) {

        mLevelChoose = new TreeLevelChoose();
        setContentView(mLevelChoose.getHoldView());

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        params.height = dm.heightPixels * 3 / 5;
        window.setAttributes(params);

        window.setGravity(Gravity.BOTTOM);
    }

    public void setOnTreeChooseCompleteListener(OnTreeChooseCompleteListener listener) {
        mLevelChoose.setOnTreeChooseCompleteListener(listener);
    }
    public static BottomDialog show(Context context) {
        return show(context, null);
    }

    public static BottomDialog show(Context context, OnTreeChooseCompleteListener listener) {
        BottomDialog dialog = new BottomDialog(context, R.style.my_bottom_dialog);
        dialog.mLevelChoose.setOnTreeChooseCompleteListener(listener);
        dialog.show();

        return dialog;
    }
    public void setDialogDismissListener(OnDialogCloseListener listener){
        mLevelChoose.setOnDialogCloseListener(listener);
    }

    /**
     *设置字体选中的颜色
     */
    public void serColorTvTabChoose(int selectedColor){
        mLevelChoose.setColorTvTabChoose(selectedColor);
    }
    /**
     *设置字体没有选中的颜色
     */
    public void serColorTvTabNormal(int unSelectedColor){
        mLevelChoose.serColorTvTabNormal(unSelectedColor);
    }
    /**
     * 设置字体的大小
     */
    public void setTvTabTextSize(float sp){
        mLevelChoose.setTvTabTextSize(sp);
    }

    /**
     * 设置指示器的背景
     */
    public void setIndicatorBackgroundColor(int colorId){
        mLevelChoose.setIndicatorBackgroundColor(colorId);
    }

    public void setDisplayChooseTree(String firstCode, int firstIndex, String secondCode, int secondIndex, String thirdCode, int thirdIndex, String fourthCode, int fourthIndex){
        mLevelChoose.getChooseTree(firstCode,firstIndex,secondCode,secondIndex,thirdCode,thirdIndex,fourthCode,fourthIndex);
    }
}

